<?php


namespace App\Kuafu\Sms\Enum;


use App\Kuafu\Base\Enum\BaseCodeEnum;
use App\Kuafu\Sms\Service\SmsService;

class SmsCacheCodeEnum extends BaseCodeEnum
{
    public const SMS_CODE_MINUTE_MAX = 1;
    public const SMS_CODE_HOUR_MAX   = 5;

    public const SMS_CODE_EXPIRE = 60;

    private const SMS_CODE_MINUTE = 'sms_code_minute:%d:%d';
    private const SMS_CODE_HOUR   = 'sms_code_hour:%d:%d';

    /**
     * 每分钟次数校验
     * @param string $type
     * @return string
     */
    public static function getSmsCodeMinutePrefix(int $mobile, int $type = SmsService::CODE_TYPE_DEFAULT): string
    {
        return sprintf(self::SMS_CODE_MINUTE, $mobile, $type);
    }

    /**
     * 一小时次次校验
     * @param string $type
     * @return string
     */
    public static function getSmsCodeHourPrefix(int $mobile, int $type = SmsService::CODE_TYPE_DEFAULT): string
    {
        return sprintf(self::SMS_CODE_HOUR, $mobile, $type);
    }
}
